$.ajax({
	type : "POST",
	url : "readHistory.do",
	dataType : 'text',

	data : {
		type : "suggestHistory",
		time : $("#time").val(),
		personId : $("#personId").val(),
	},

	success : function(data) {

		//if (checkID($("#id").val())) {
		var str = data.split("|");
		if (str[0] == "nodata") { //資料庫無此資料
			alert(str[1]);
			location.reload();
		} else {
			// sex radio
			if (str[0] == "male")
				$('input[name=sex]').get(0).checked = true;
			else if (str[0] == "female")
				$('input[name=sex]').get(1).checked = true;
			else
				$('input[name=sex]').attr("checked", false);
			// weightType
			if (str[1] == "old")
				$('input[name=weightType]').get(0).checked = true;
			else if (str[1] == "new")
				$('input[name=weightType]').get(1).checked = true;
			else
				$('input[name=weightType]').attr("checked", false);
			// work radio
			if (str[2] == "little")
				$('input[name=work]').get(0).checked = true;
			else if (str[2] == "middle")
				$('input[name=work]').get(1).checked = true;
			else if (str[2] == "large")
				$('input[name=work]').get(2).checked = true;
			else
				$('input[name=work]').attr("checked", false);
			// activity radio
			if (str[3] == "little")
				$('input[name=activity]').get(0).checked = true;
			else if (str[3] == "middle")
				$('input[name=activity]').get(1).checked = true;
			else if (str[3] == "large")
				$('input[name=activity]').get(2).checked = true;
			else
				$('input[name=activity]').attr("checked", false);
			// select data
			if (str[4]) {
				var getdata = str[4].split(";");
				for ( var i = 0; i < getdata.length; i++) {
					if (getdata[i])
						nourish_list(getdata[i]); // 營養品攝取份量計算
				}
			}
			// text data
			for ( var i = 5; i < str.length; i++) {
				var getdata = str[i].split(":");
				$(getdata[0]).val(getdata[1]);
			}

			get_sqldata($('input[name=sex]:checked').val(), 
					$('input[name=weightType]:checked').val(), 
					$('input[name=work]:checked').val(), 
					$('input[name=activity]:checked').val());

			Total_intake();
		}
	}
});